package com.yyds.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yyds.common.MyJSON;
import com.yyds.mapper.NatSitesMapper;
import com.yyds.pojo.NatSites;
import com.yyds.service.NatSitesService;
import com.yyds.vo.EchartPieVo;
import com.yyds.vo.NatHospitalVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 请不要模仿我
 *
 * @author lxy
 * com.yyds.service.impl.
 */
@Service
public class NatSitesServiceImpl implements NatSitesService {
    @Autowired
    private NatSitesMapper mapper;

    @Override
    public MyJSON<NatHospitalVo> findAllNatSites(Map<String,Object> params) {
        Integer page = Integer.parseInt(params.get("page")+"");
        Integer limit = Integer.parseInt(params .get("limit")+"");

        PageHelper.startPage(page,limit);
        List<NatHospitalVo> natHospitals =  mapper.findAllNatSites(params);

        // mybatis 的分页数据结构
        PageInfo<NatHospitalVo> natHospitalPageInfo = new PageInfo<>(natHospitals);
        // 把mybatis 的分页数据结构中的 数据 封装到 layui的 分页数据结构中
        MyJSON<NatHospitalVo> natHospitalVo = new MyJSON<>();
        natHospitalVo.setCode(0);
        natHospitalVo.setMsg("学生分页列表数据");
        natHospitalVo.setCount(natHospitalPageInfo.getTotal());  // 总记录数
        natHospitalVo.setData(natHospitalPageInfo.getList());  // 分页列表数据

        return natHospitalVo;
    }

    @Override
    public int deleteByPrimaryKey(Integer sitesId) {

        return mapper.deleteByPrimaryKey(sitesId);
    }

    @Override
    public int insert(NatSites record) {

        return mapper.insert (record);
    }

    @Override
    public int insertSelective(NatSites record) {

        return mapper.insertSelective(record);
    }

    @Override
    public NatSites selectByPrimaryKey(Integer sitesId) {

        return mapper.selectByPrimaryKey(sitesId);
    }

    @Override
    public int updateByPrimaryKeySelective(NatSites record) {

        return mapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(NatSites record) {

        return mapper.updateByPrimaryKey(record);
    }

    @Override
    public List<Integer> findHospital() {

        return mapper.findHospital();
    }

    @Override
    public List<Integer> addfindAllDoctor(@RequestParam Map<String,Object> params) {
        String hospitalId = params.get("key")+"";
        Integer id=0;
        if(hospitalId!="" & hospitalId!=null){
            id = Integer.parseInt(hospitalId);
        }else{
            id=-1;
        }
        return mapper.selectDoctorByKey(id);
    }

    @Override
    public List<EchartPieVo> personData() {

        return mapper.countData();
    }

    @Override
    public int deleteAll(String str) {
        List<Integer> list = new ArrayList();
        String[] split = str.split("-");
        for (String s : split) {
            list.add(Integer.valueOf(s));
        }
        return mapper.deleteAll(list);
    }


}
